import Vue from 'vue'
import { AppState } from '@/store/modules/app/typings'
import { LOGOUT, OAUTH_TOKEN, INFO } from '@/store/modules/app/keys'

export default {
  pending (state: AppState, { key, status }: { key: string, status: boolean }) {
    Vue.set(state.pending, key, status)
  },

  [OAUTH_TOKEN] (state: AppState, payload: any = {}) {
    state.access_token = payload.access_token
    state.refresh_token = payload.refresh_token
    if (payload.access_token) {
      window.sessionStorage.setItem('dev:access_token', payload.access_token)
    } else {
      window.sessionStorage.removeItem('dev:access_token')
    }
  },

  [LOGOUT] (state: AppState) {
    state.access_token = undefined
    state.user = undefined
    // window.sessionStorage.removeItem('dev:access_token')
  },

  [INFO](state: AppState, {key, value}: {key: string, value: string}){
    if (key==='menuLiudaoName') {
      state.menuLiudaoName = value
    }
  }
}
